package model;

import model.area.AreaManagement;
import model.area.Field;
import model.financial.FinancialManagement;
import model.game.Match;
import model.game.Team;
import model.game.TeamManagement;
import model.person.Function;
import model.person.Person;
import model.person.PersonManagement;

public class FCEverritsen {
	private static FCEverritsen uniqueInstance;
	private AreaManagement areaManagement;
	private FinancialManagement financialManagement;
	private TeamManagement teamManagement;
	private PersonManagement personManagement;

	private FCEverritsen() {
		this.areaManagement = new AreaManagement();
		this.financialManagement = new FinancialManagement();
		this.teamManagement = new TeamManagement();
		this.personManagement = new PersonManagement();
	}

	public static FCEverritsen getInstance() {
		if (uniqueInstance == null) {
			uniqueInstance = new FCEverritsen();
		}
		return uniqueInstance;
	}

	public void createPerson(String firstName, String lastName, int salary,
			Function... functions) {
		personManagement.addEmployee(firstName, lastName, salary, functions);

	}

	public void createPerson(String firstName, String lastName) {
		personManagement.addMember(firstName, lastName);

	}

	public void createOwnTeam(String teamName) {
		teamManagement.addOwnTeam(teamName);

	}

	public void createOtherTeam(String teamName) {
		teamManagement.addOtherTeam(teamName);

	}

	public void addPersonToTeam(String fullName, String teamName) {
		Person person = personManagement.getPersonByFullName(fullName);
		teamManagement.addPersonToOwnTeam(person, teamName);

	}

	public void addField(String fieldName, int rent, boolean isArtificialGrass) {
		areaManagement.addField(fieldName, rent, isArtificialGrass);

	}

	public void addMatch(String teamA, String teamB, String fieldName,
			String startTime) {
		Team tA = teamManagement.getTeam(teamA);
		Team tB = teamManagement.getTeam(teamB);
		Field f = areaManagement.getField(fieldName);
		teamManagement.addMatch(tA, tB, f, startTime);
	}

	public void addBuilding(String buildingName, int rent, int serviceCosts) {
		areaManagement.addBuilding(buildingName, rent, serviceCosts);
	}

	public void addReservation(String startDate, String stopDate,
			String contactPerson, String... areas) {
		Person p = personManagement.getPersonByFullName(contactPerson);
		areaManagement.addReservation(startDate, stopDate, p, areas);

	}

	public void addBill(int amount, String date, String fullName) {
		Person p = personManagement.getPersonByFullName(fullName);
		financialManagement.addBill(amount, date, p);

	}

	public void addGoal(String teamName, String startTime) {
		teamManagement.addGoal(teamName, startTime);

	}

	public void addYellowCard(String teamName, String startTime, String fullName) {
		Person p = personManagement.getPersonByFullName(fullName);
		Match m = teamManagement
				.getMatchByNameAndStartTime(teamName, startTime);
		m.addYellowCard(p);

	}

	public void addRedCard(String teamName, String startTime, String fullName) {
		Person p = personManagement.getPersonByFullName(fullName);
		Match m = teamManagement
				.getMatchByNameAndStartTime(teamName, startTime);
		m.addRedCard(p);

	}

	public void addRefereeToMatch(String teamName, String startTime,
			String refereeName) {
		Person ref = personManagement.getPersonByFullName(refereeName);
		Match m = teamManagement
				.getMatchByNameAndStartTime(teamName, startTime);
		teamManagement.addRefereeToMatch(m, ref);
	}

	public void printAreaData() {
		System.out.println(areaManagement.getAreaData());
	}

	public void handleBill(String fullName, String date) {
		Person person = personManagement.getPersonByFullName(fullName);
		financialManagement.handleBill(person, date);
	}

	public void archiveBill(String fullName, String date) {
		Person person = personManagement.getPersonByFullName(fullName);
		financialManagement.archiveBill(person, date);
	}

	public void printBillData() {
		System.out.println(financialManagement.getBillData());
	}

	public void printTeamData() {
		System.out.println(teamManagement.getTeamData());
	}
}
